/*====================================================================================
                                                                     
		Financial Constraints and Propagation of Shocks in Production Networks
			    By Demir-Javorcik-Michalski-Ors
  
*====================================================================================*/	

clear all
set more off
log close _all
set matsize 5000

cd "\data\" // Add your directory here

/***************************************
Table II.6
***************************************/
use tempall.dta,clear

* Drop outliers in terms of sales growth 
bys year ,sort: egen p5=pctile(Chgsales),p(5)
bys year ,sort: egen p95=pctile(Chgsales),p(95)
keep if  Chgsales>p5 & Chgsales<p95

keep if year==2012

reghdfe  FirmExposure BartikExposure if ImpShr0>0,absorb( sr ) vce(cluster sr)
estimates store col1
estadd local FE "sr" , replace
estadd local cluster "sr", replace

reghdfe  FirmExposure BartikExposure lnEmp0 ImpShr0 if ImpShr0>0,absorb( sr ) vce(cluster sr)
estimates store col2
estadd local FE "sr" , replace
estadd local cluster "sr", replace

reghdfe  FirmExposure BartikExposure,absorb( sr ) vce(cluster sr)
estimates store col3
estadd local FE "sr" , replace
estadd local cluster "sr", replace

reghdfe  FirmExposure BartikExposure lnEmp0 ImpShr0,absorb( sr ) vce(cluster sr)
estimates store col4
estadd local FE "sr" , replace
estadd local cluster "sr", replace

esttab col1 col2 col3 col4,  compress width(1\hsize)  se  star(* 0.10 ** 0.05 *** 0.01) s(N r2 cluster   FE )


/***************************************
Table II.7
***************************************/

reghdfe  Chgsales ChgTau_Firm ImpShr0 lnEmp0   ,absorb( sr) vce(cluster sr)
estimates store col1
estadd local FE "sr" , replace
estadd local cluster "sr", replace

reghdfe  Chgsales ImpShr0 lnEmp0 (ChgTau_Firm=ChgTau_Bartik)  ,absorb( sr) vce(cluster sr)  
estimates store col2
estadd local FE "sr" , replace
estadd local cluster "sr", replace
estadd scalar testrkf=e(rkf): col2
estadd scalar testidstat=e(idstat): col2

reghdfe  Chgsales ChgTau_Bartik ImpShr0 lnEmp0   ,absorb( sr) vce(cluster sr)
estimates store col3
estadd local FE "sr" , replace
estadd local cluster "sr", replace

esttab col1 col2 col3,  compress width(1\hsize)  se  star(* 0.10 ** 0.05 *** 0.01) s(N r2 cluster   FE testrkf testidstat)

/***************************************
Table II.1
***************************************/

gen LowFinCost=1-LiqCons

su FirmExposure BartikExposure  LowFinCost,det
su FirmExposure BartikExposure  LowFinCost if ImpShr0>0,det
